<?php
  
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit; 

/**
 * Lazyest_Shortcodes
 * Shortcodes for Lazyest Gallery
 * 
 * @package Lazyest Gallery
 * @subpackage Shortcodes
 * @author Marcel Brinkkemper
 * @copyright 2013 Brimosoft
 * @since 2.0.0 (r440)
 * @version 2.0.0 (r443)
 * @access public
 */
class Lazyest_Shortcodes {
	
	/**
	 * @staticvar Lazyest_Shortcodes $instance single instance in memory
	 */ 
	private static $instance;
	
	/**
	 * @var array $cameras with id for camera slideshow elements
	 * @access private
	 */
	private $cameras = array();
	
	/**
	 * Lazyest_Shortcodes::__construct()
	 * 
	 * @return void
	 */
	function __construct() {}
	
	/**
	 * Lazyest_Shortcodes::init()
	 * 
	 * @return void
	 */
	function init() {
		$this->actions();
		$this->shortcodes();
	}
	
	/**
	 * Lazyest_Shortcodes::instance()
	 * 
	 * @return object Lazyest_Shortcodes
	 */
	public static function instance() {
		if ( ! isset( self::$instance ) ) {
			self::$instance = new Lazyest_Shortcodes;
			self::$instance->init();
		}
		return self::$instance;
	}
	
	/**
	 * Lazyest_Shortcodes::actions()
	 * 
	 * @uses add_action()
	 * @return void
	 */
	function actions() {
		add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts'       ),  50 );
		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_camera_style'   )      );		
		add_action( 'wp_footer',          array( $this, 'camera_scripts'         ), 100 );
	}
	
	/**
	 * Lazyest_Shortcodes::register_scripts()
	 * 
	 * @since 2.0.0 (r440)
	 * @uses wp_script_is()
	 * @uses wp_register_script()
	 * @return void
	 */
	function register_scripts() {
		$j = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'js' : 'min.js';
		if ( ! wp_script_is( 'jquery-easing', 'registered' ) )		
			wp_register_script( 'jquery-easing', lazyest_gallery()->plugin_url . "/frontend/js/jquery.easing.1.3.$j", array( 'jquery' ), '1.3', true );		
		if ( ! wp_script_is( 'camera-slide', 'registered' ) )			
			wp_register_script( 'camera-slide', lazyest_gallery()->plugin_url . "/frontend/js/camera.$j", array( 'jquery', 'jquery-easing' ), '1.3.3', true );	
	}
	
	/**
	 * Lazyest_Shortcodes::has_shortcode()
	 * Check if content has slideshow shortcode
	 * 
	 * @since 2.0.0 (r440)
	 * @uses get_post()
	 * @uses get_the_ID()
	 * @uses WP_Post
	 * @param string $shortcode
	 * @return bool
	 */
	private function has_shortcode( $shortcode = '' ) {
		$has_shortcode = false;
		
		if ( ! empty( $shortcode ) ) {
			$this_post = get_post( get_the_ID() );
			if ( stripos($this_post->post_content, '[' . $shortcode) !== false )
        $has_shortcode = true; 
     }   	
		return $has_shortcode;
	}
	
	/**
	 * Lazyest_Shortcodes::shortcodes()
	 * Hook shortcode tags
	 * Lazyest Gallery supports the following shortcodes:
	 * 
	 * [lazyest_gallery]
	 * [lazyest_folder]
	 * [lazyest_slideshow]
	 * 
	 * for compatibilty sake, the following shortcodes are supported:
	 * [lg_gallery]
	 * [lg_folder]
	 * [lg_image]
	 * [lg_slideshow]
	 * 
	 * @since 2.0.0 (r440)
	 * @uses add_shrtcode
	 * @return void
	 */
	function shortcodes() {
		add_shortcode( 'lazyest_gallery',   array( $this, 'gallery_shortcode'   ) );
		
		add_shortcode( 'lg_gallery',        array( $this, 'lg_gallery_shortcode'   ) );

		add_shortcode( 'lazyest_folder',    array( $this, 'folder_shortcode'    ) );
		add_shortcode( 'lg_folder',         array( $this, 'lg_folder_shortcode'    ) );

		// lg_image is supported for back-compat reasons only. Use WordPress Media to insert images.
		add_shortcode( 'lg_image',          array( $this, 'lg_image_shortcode'     ) );

		add_shortcode( 'lazyest_slideshow', array( $this, 'slideshow_shortcode' ) );
		add_shortcode( 'lg_slideshow',      array( $this, 'lg_slideshow_shortcode' ) );
	}
	
	
	/**
	 * Lazyest_Shortcodes::gallery_shortcode()
	 * The Lazyest Gallery shortcode
	 * use <code>[lazyest_gallery]</code>
	 * @see http://codex.wordpress.org/Gallery_Shortcode for attributes
	 * Extra attribute: <code>'root="afolder/"'</code> to set nother root folder
	 * 
	 * Plugins may override the lazyest_gallery shortcode
	 * <code>'lazyest_gallery'</code>
	 * 
	 * WordPress filters used:
	 * <code>'use_default_gallery_style'</code>
	 * <code>'gallery_style'</code>
	 * 
	 * Action to <strong>echo</strong> content:
	 * <code>'lazyest_gallery_end_of_gallery'</code>
	 * 
	 * @since 2.0.0 (r440)
	 * @uses apply_filters()
	 * @uses sanitize_sql_orderby()
	 * @uses shortcode_atts()
	 * @uses intval()
	 * @uses get_permalink()
	 * @uses WP_Query
	 * @uses esc_attr()
	 * @uses the_title_attribute()
	 * @uses wp_reset_query()
	 * @uses wp_reset_postdata()
	 * @uses get_pagenum_link()
	 * @param array $attr
	 * @return string html markup for lazyest-gallery
	 */
	function gallery_shortcode( $attr ) {	
		
		static $instance = 0;
		$instance++;
	
		if ( ! empty( $attr['ids'] ) ) {
			// 'ids' is explicitly ordered, unless you specify otherwise.
			if ( empty( $attr['orderby'] ) )
				$attr['orderby'] = 'post__in';
			$attr['include'] = $attr['ids'];
		}
		if ( ! defined( 'LAZYEST_GALLERY_SHORTCODE' ) )
			define( 'LAZYEST_GALLERY_SHORTCODE', true );
		// Allow plugins/themes to override the default gallery template.
		$output = apply_filters( 'lazyest_gallery', '', $attr );
		if ( $output != '' )
			return $output;
		
		// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
		if ( isset( $attr['orderby'] ) ) {
			$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
			if ( !$attr['orderby'] )
				unset( $attr['orderby'] );
		}
		
		list( $default_orderby, $default_ascdesc ) = explode( '-', lazyest_gallery()->sort_by() );
		$order_by = lazyest_gallery()->sort_by() == 'menu_order-ASC' ? 'menu_order' :  substr( $default_orderby[0], 5 );
	
		extract( shortcode_atts( array(
			'order'      => $default_ascdesc,
			'orderby'    => $default_orderby,
			'id'         => 0,
			'itemtag'    => 'dl',
			'icontag'    => 'dt',
			'captiontag' => 'dd',
			'columns'    => lazyest_gallery()->get_option( 'folder_columns' ),
			'size'       => 'thumbnail',
			'include'    => '',
			'exclude'    => '',
			'root'       => ''
		), $attr ) );
	
		$id = intval($id);
		if ( 'RAND' == $order )
			$orderby = 'none';
		
		//user has set a root folder (text)
		if ( ! empty( $root ) ) {
			$id = lazyest_folderbase()->get_folder_by_string( $root );
		}		
				
		$args = array (
			'post_type'      => lazyest_gallery()->post_type,
			'post_parent'    => $id,
			'order'          => $order,
			'orderby'        => $orderby,
			'posts_per_page' => lazyest_gallery()->get_option( 'folders_page' )
		);
		
		if ( ! empty( $include ) ) {
			$include = str_replace( ' ', '', $include );
			$args['post__in'] = explode( ',', $include );
		}
		if ( ! empty( $exclude ) ) {
			$exclude = str_replace( ' ', '', $exclude );
			$args['post__not_in'] = explode( ',', $exclude );
		}
		global $paged;
		if ( ! $paged )
			$paged = 1;
		if ( 1 < $paged )
			$args['paged'] = $paged;		
	
		lazyest_frontend()->itemtag    = $itemtag;
		lazyest_frontend()->icontag    = $icontag;
		lazyest_frontend()->captiontag = $captiontag;
	
		$selector = "gallery-{$instance}";
	
		$gallery_style = $gallery_div = '';
		if ( apply_filters( 'use_default_gallery_style', true ) )
			$gallery_style = lazyest_frontend()->gallery_style( $selector );
		$classes = lazyest_frontend()->gallery_class( 'archive' );
		$gallery_div = "<div id='$selector' class='$classes'>";
		
		$output =  apply_filters( 'lazyest_folder_shortcode_title', '<h3>' . lazyest_gallery()->gallery_title() . '</h3>' );
		$output .= apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
		
		if ( ! defined( 'DOING_GALLERYFOLDERS' ) )
			define( 'DOING_GALLERYFOLDERS', true );
		$i = 0;
		
		$global_post = $GLOBALS['post'];
		$query = new WP_Query( $args );
		
		global $post;
		while( $query->have_posts() ) {
			$query->the_post();
			$thumbnail = lazyest_frontend()->folder_thumbnail_html();
			$link = '<a href="' . get_permalink() . '" title="' . esc_attr( sprintf( __( 'View folder &#8220;%s&#8221;', 'lazyest-gallery' ), the_title_attribute( 'echo=0' ) ) ) . '" rel="bookmark">' . $thumbnail . '</a>';
			$output .= "<{$itemtag} class='gallery-item folder-item'>";			
			ob_start();
			do_action( 'lazyest_gallery_before_folder_icon', $post->ID );
			$output .= ob_get_contents();
			ob_end_clean();
			$output .= "
				<{$icontag} class='gallery-icon folder-icon'>
					$link
				</{$icontag}>";
			ob_start();
			do_action( 'lazyest_gallery_after_folder_icon', $post->ID );
			$output .= ob_get_contents();
			ob_end_clean();
			$output .= "</{$itemtag}>";
			if ( $columns > 0 && ++$i % $columns == 0 )
				$output .= '<br style="clear: both" />';
		}
	
		$output .= "
				<br style='clear: both;' />";
		ob_start();
		do_action( 'lazyest_gallery_end_of_gallery' );
		$output .= ob_get_contents();
		ob_end_clean();		
		$output .=	"
			</div>\n";
		
		$nextpage = $prevpage = 0;	
		if ( 1 < $query->max_num_pages ) {
			$nextpage = $paged + 1;
			$prevpage = $paged - 1;
			$nextpage = ( $nextpage <= $query->max_num_pages ) ? $nextpage : 0;
		}
		
		wp_reset_query();
		wp_reset_postdata();
		$GLOBALS['post'] = $global_post;
		
		// get page links if more folders than folders per page		
		$nextpage_link = $prevpage_link = '';
		if ( $prevpage ) {
			$prevpage_link = "<span class='meta-nav'>&larr;</span> <a href='" . get_pagenum_link( $prevpage ) . "'>" . __( 'Previous folders page', 'lazyest-gallery' ) . "</a>";
		}
		if ( $nextpage ) {
			$nextpage_link = "<a href='" . get_pagenum_link( $nextpage ) . "'>" . __( 'Next folders page', 'lazyest-gallery' ) . "</a> <span class='meta-nav'>&rarr;</span>";
		}
		$output .= "
			<nav id='nav-below'>
				<h3 class='assistive-text'>" . __( 'Folder navigation', 'lazyest-gallery' ) . "</h3>
				<div class='nav-previous alignleft'>$prevpage_link</div>
				<div class='nav-next alignright'>$nextpage_link</div>
			</nav>
		";
						
		return $output;			
	}
	
	/**
	 * Lazyest_Shortcodes::folder_shortcode()
	 * The Lazyest Folder shortcode
	 * use [lazyest_folder folder="folder/folder/"] or [lazyest_folder id="15"]
	 * where id= refers to post->ID
	 * @see http://codex.wordpress.org/Gallery_Shortcode for attributes
	 * 
	 * Uses filter for plugins to override the shortcode:
	 * <code>'lazyest_folder'</code>
	 * Filter for h3 title element:
	 * <code>'lazyest_folder_shortcode_title'</code>
	 * 
	 * Actions to <strong>echo</strong> extra content:
	 * <code>'lazyest_gallery_before_folder_content'</code> 
	 * <code>'lazyest_gallery_after_folder_content'</code>
	 * 
	 * @since 2.0.0 (r440)
	 * @uses esc_html()
	 * @uses apply_filters()
	 * @uses sanitize_sql_orderby(
	 * @uses do+_action()
	 * @param mixed $attr
	 * @return string html markup for folder gallery
	 */
	function folder_shortcode( $attr ) {
			if( ! isset( $attr[0] ) )
				$attr[0] = 'lazyest_folder';
				
		if ( isset( $attr['folder'] ) && ! isset( $attr['id'] ) ) {			
			$attr['id'] = lazyest_folderbase()->get_folder_by_string( $attr['folder'] );
			if ( ! isset( $attr['id'] ) || ! $attr['id']) {
				if ( isset( $attr['folder'] ) ) {
					return '<p class="error">' . sprintf( __( 'Apologies, but no results were found for folder &#8220;%s&#8221; in shortcode <code>[%s folder="%s"]</code>.', 'lazyest-gallery' ),					 
						esc_html( $attr['folder'] ),
						$attr[0],
						esc_html( $attr['folder'] ) 
						) . '</p>';
				} else	{	
					return '<p class="error">' . sprintf( __( 'Apologies, but no folder could be matched in shortcode <code>[%s]</code>', 'lazyest-gallery' ), $attr[0] ) . '</p>';
				}
			}
		}		
		if ( ! defined( 'LAZYEST_GALLERY_SHORTCODE' ) )
			define( 'LAZYEST_GALLERY_SHORTCODE', true );
		
		$output = apply_filters( 'lazyest_folder', '', $attr );
		if ( $output != '' )
			return $output;
	
		// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
		if ( isset( $attr['orderby'] ) ) {
			$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
			if ( !$attr['orderby'] )
				unset( $attr['orderby'] );
		}
		
		list( $default_orderby, $default_ascdesc ) = explode( '-', lazyest_gallery()->sort_by( 'thumbnails' ) );
		$order_by = lazyest_gallery()->sort_by( 'thumbnails' ) == 'menu_order-ASC' ? 'menu_order' :  substr( $default_orderby[0], 5 );
	
		extract( shortcode_atts( array(
			'order'      => $default_ascdesc,
			'orderby'    => $default_orderby,
			'id'         => 0,
			'itemtag'    => 'dl',
			'icontag'    => 'dt',
			'captiontag' => 'dd',
			'columns'    => lazyest_gallery()->get_option( 'thumbs_columns' ),
			'size'       => 'thumbnail'
		), $attr ) );
	
		$id = intval( $id );
		if ( 'RAND' == $order )
			$orderby = 'none';
		
		if ( $orderby != $default_orderby ) {
			if ( ! in_array( $orderby, array( 'none', 'menu_order' ) ) )
				$orderby = 'post_' . $orderby;
		}
		lazyest_gallery()->change_option( 'sort_thumbnails', "$orderby-$order" );
		lazyest_gallery()->change_option( 'thumbs_columns',  $columns          );
		lazyest_frontend()->itemtag    = $itemtag;
		lazyest_frontend()->icontag    = $icontag;
		lazyest_frontend()->captiontag = $captiontag;
		
		$global_post = $GLOBALS['post'];
		
		$output = '';
		global $post;
		if ( $folder = get_post( $id ) ) {
			$post = $folder;
			
			$folder_title = apply_filters( 'lazyest_folder_shortcode_title', '<h3>' . get_the_title() . '</h3>' );
			ob_start(); // buffer to use actions that echo content
			?>
			<?php echo $folder_title ?>
			<div class="lazyest-gallery">
				<?php do_action( 'lazyest_gallery_before_folder_content' ); // this action is used for breadcrumb trail and for thumbnail images ?>
				<?php	// we don't echo content in a folder shortcode ?>
				<?php do_action( 'lazyest_gallery_after_folder_content'  ); // this action is used for extra fields and for subfolders ?>
			</div>
			
			<?php
			$output = ob_get_contents();
			ob_end_clean();
		}
		$GLOBALS['post'] = $global_post;
		
		return $output;
	}
	
	/**
	 * Lazyest_Shortcodes::enqueue_camera_scripts()
	 * Enqueue scripts for camera slideshow
	 * 
	 * @since 2.0.0 (r440)
	 * @uses wp_enqueue_script()
	 * @return void
	 */
	function enqueue_camera_scripts() {
			wp_enqueue_script( 'jquery-easing' );
			wp_enqueue_script( 'camera-slide' );
	}
	
	/**
	 * Lazyest_Shortcodes::enqueue_camera_style()
	 * Enqueue stylesheet for camera slideshow script
	 * The slideshow will not run on home page or archive pages
	 * 
	 * @since 2.0.0 (r440)
	 * @uses is_single()
	 * @uses wp_enqueue_style()
	 * @return void
	 */
	function enqueue_camera_style() {
		// slideshow runs only for single posts or pages
		if ( ! is_single() )
			return;
					
		if ( $this->has_shortcode( 'lazyest_slideshow' ) || $this->has_shortcode( 'lg_slideshow' ) )
			wp_enqueue_style( 'lazyest-slideshow', lazyest_gallery()->plugin_url . '/frontend/css/camera.css', '2.0.0-r440' );		
	}
	
	/**
	 * Lazyest_Shortcodes::camera_scripts()
	 * Adds javascript in wp_footer to start the slideshow(s)
	 * 
	 * @since 2.0.0 (r440)
	 * @return void
	 */
	function camera_scripts() {
		if ( empty( $this->cameras ) )
			return;
		foreach( $this->cameras as $id ) {
			?>
		<script type="text/javascript">
			(function($) {	
				$('#camera_wrap_<?php echo $id ?>').camera({ thumbnails: true });
			})(jQuery)
		</script>
			<?php			
		}	
	}
	
	/**
	 * Lazyest_Shortcodes::data_image()
	 * Return src attribute for images in the slideshow
	 * 
	 * @since 2.0.0 (r440)
	 * @uses wp_get_attachment_image_src()
	 * @uses WP_Post
	 * @param string $size
	 * @return string
	 */
	private function data_image( $size = 'thumbnail' ) {
		global $post;
		$wp_src = wp_get_attachment_image_src( $post->ID, $size );
		return $wp_src[0];
	}
	
	/**
	 * Lazyest_Shortcodes::slideshow_shortcode()
	 * Slideshow shortcode
	 * use <code>[lazyest_slideshow folder="folder/folder/"]</code>
	 * or <code>[lazyest_slideshow id="10"]</code>
	 * where id= $post->ID
	 * 
	 * Uses filter for plugins to override the shortcode:
	 * <code>'lazyest_slideshow'</code>
	 * 
	 * supported attributes:
	 * folder= (directory path or page-path)
	 * id= post ID
	 * orderby= (post_date,post_name,menu_order,...) default: see Lazyest Gallery settings
	 * order= (ASC,DESC)
	 * size= (thumbnail,medium,large,full) default: "large"
	 * skin= (amber,ash,azure,beige,black,blue,brown,burgundy,charcoal,chocolate,
	 *        coffee,cyan,fuchsia,gold,green,grey,indigo,khaki,lime,magenta,
	 *        maroon,orange,olive,pink,pistachio,red,tangerine,turquoise,
	 *        violet,white,yellow) default: "ash"
	 * 
	 * @uses Camera slideshow v1.3.3 - a jQuery slideshow with many effects, transitions, easy to customize, using canvas and mobile ready, based on jQuery 1.4+
	 * @copyright 2012 by Manuel Masia - www.pixedelic.com
	 * @see http://www.pixedelic.com/plugins/camera/    
	 * 
	 * @since 2.0.0 (r440)
	 * @uses is_single()
	 * @uses esc_html()
	 * @uses sanitize_sql_orderby()
	 * @uses shortcode_atts()
	 * @uses WP_Query
	 * @uses the_excerpt()
	 * @uses wp_reset_query()
	 * @uses wp_reset_postdata()
	 * @param mixed $attr 
	 * supported attributes:
	 * folder= (directory path or page-path)
	 * id= post ID
	 * orderby= (post_date,post_name,menu_order,...) default: see Lazyest Gallery settings
	 * order= (ASC,DESC)
	 * size= (thumbnail,medium,large,full) default: "large"
	 * skin= (amber,ash,azure,beige,black,blue,brown,burgundy,charcoal,chocolate,
	 *        coffee,cyan,fuchsia,gold,green,grey,indigo,khaki,lime,magenta,
	 *        maroon,orange,olive,pink,pistachio,red,tangerine,turquoise,
	 *        violet,white,yellow) default: "ash"
	 * 
	 * @return string html markup for camera slideshow
	 */
	function slideshow_shortcode( $attr ) {
		
		if ( ! is_single() )
			return '';
			
		if ( isset( $attr['folder'] ) && ! isset( $attr['id'] ) ) {			
			$attr['id'] = lazyest_folderbase()->get_folder_by_string( $attr['folder'] );
			if ( ! isset( $attr['id'] ) || ! $attr['id']) {
				if ( isset( $attr['folder'] ) ) {
					return '<p class="error">' . sprintf( __( 'Apologies, but no results were found for folder &#8220;%s&#8221; in shortcode <code>[%s folder="%s"]</code>.', 'lazyest-gallery' ),					 
						esc_html( $attr['folder'] ),
						$attr[0],
						esc_html( $attr['folder'] ) 
						) . '</p>';
				} else	{
					if( ! isset( $attr[0] ) )
						$attr[0] = 'lazyest_folder';	
					return '<p class="error">' . sprintf( __( 'Apologies, but no folder could be matched in shortcode <code>[%s]</code>', 'lazyest-gallery' ), $attr[0] ) . '</p>';
				}
			}
		}
				
		if ( ! defined( 'LAZYEST_GALLERY_SHORTCODE' ) )
			define( 'LAZYEST_GALLERY_SHORTCODE', true );
		
		$output = apply_filters( 'lazyest_sllideshow', '', $attr );
		if ( $output != '' )
			return $output;
	
		// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
		if ( isset( $attr['orderby'] ) ) {
			$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
			if ( !$attr['orderby'] )
				unset( $attr['orderby'] );
		}
		
		list( $default_orderby, $default_ascdesc ) = explode( '-', lazyest_gallery()->sort_by( 'thumbnails' ) );
		$order_by = lazyest_gallery()->sort_by( 'thumbnails' ) == 'menu_order-ASC' ? 'menu_order' :  substr( $default_orderby[0], 5 );
	
		extract( shortcode_atts( array(
			'order'      => $default_ascdesc,
			'orderby'    => $default_orderby,
			'id'         => 0,
			'size'       => 'large',
			'skin'       => 'ash'
		), $attr ) );
	
		$id = intval($id);
		if ( 'RAND' == $order )
			$orderby = 'none';
					
		$global_post = $GLOBALS['post'];
		$args =	array( 'post_type' => 'attachment', 'post_parent' => $id, 'post_mime_type' => 'image', 'orderby' => $orderby, 'order' => $order, 'post_status' => array( 'publish', 'inherit' ) );
		$query = new WP_Query( $args );	
		?>
		<div class="fluid_container">
			<div class="camera_wrap camera_<?php echo $skin ?>_skin" id="camera_wrap_<?php echo $id ?>">
			<?php while( $query->have_posts() ) :	$query->the_post(); ?>
			<div data-thumb="<?php echo $this->data_image( 'thumbnail' ) ?>" data-src="<?php echo $this->data_image( $size ) ?>">
          <div class="camera_caption fadeFromBottom">
             <?php the_excerpt() ?>
          </div>
      </div>
			<?php endwhile; ?>
		</div>
		<br style="clear:both;"/>
		<?php
		
		wp_reset_query();
		wp_reset_postdata();
		$GLOBALS['post'] = $global_post;
		
		$this->cameras[] = $id;
		$this->enqueue_camera_scripts();
	}
	
	// functions for pre-2.0 shortcodes ------------------------------------------	
	/**
	 * Lazyest_Shortcodes::lg_gallery_shortcode()
	 * Compatibility for <code>[lg_gallery]</code> shortcodes 
	 * @see Lazyest_Shortcodes::gallery_shortcode()
	 * 
	 * @deprecated 2.0.0
	 * @since 0.11.0
	 * @param array $attr
	 * @return string
	 */
	function lg_gallery_shortcode( $attr ) {
		$attr[0] = 'lg_gallery';
		return $this->gallery_shortcode( $attr );
	}
	
	/**
	 * Lazyest_Shortcodes::lg_folder_shortcode()
	 * Support for the <code>[lg_folder]</code> shortcode
	 * 
	 * @see Lazyest_Shortcodes::folder_shortcode()
	 * @deprecated 2.0.0
	 * @deprecated use the [lazyest_folder] shortcode
	 * 
	 * @since 0.11.0
	 * @param mixed $attr
	 * @return string html markup for folder gallery
	 */
	function lg_folder_shortcode( $attr ) {
		$attr[0] = 'lg_folder';
		return $this->folder_shortcode( $attr );
	}
	
	/**
	 * Lazyest_Shortcodes::lg_image_shortcode()
	 * Support for the <code>[lg_image]</code> shortcode
	 * 
	 * @deprecated 2.0.0
	 * @deprecated Use the WordPress Media Manager to insert images in your posts
	 * 
	 * @since 0.11.0 
	 * @param array $attr
	 * attributes supported:
	 * folder= folder directory path 
	 * image= image filename like "myimage.jpg"
	 * align= (left,center,right,none)
	 * display= (thumb,slide,image) parsed to: (thumbnail,large,full)
	 * @uses shortcode_atts()
	 * @uses get_post()
	 * @uses get_posts()
	 * @uses sanitize_file_name()
	 * @uses wp_get_attachment_image_src()
	 * @uses esc_html()
	 * @return string html markup for image
	 */
	function lg_image_shortcode( $attr ) {
		extract( shortcode_atts( array(
			'folder' => '',
			'image'  => '',
			'align'  => 'none',
			'display' => 'slide'
		), $attr ) );
		
		if ( ! in_array( $align, array( 'left', 'right', 'center', 'none' ) ) )
			$align = 'none';
			
		switch( $display ) {
			case 'thumb' :
				$display = 'thumbnail';
				break;
			case 'slide' :
				$display = 'large';
				break;
			case 'image' :
				$display = 'full';
				break;
			default :
				$display = 'medium';								
		}	
				
		$post_id = 0;
		if ( ! empty( $folder ) ) {
			// try to find the folder				
			$post_id = lazyest_folderbase()->get_folder_by_string( $folder );
			if ( ! $post_id )
				return '<p class="error">' . sprintf( __( 'Apologies, but no folder could be matched in shortcode <code>[lg_image folder="%s" image="%s"]</code>', 'lazyest-gallery' ), esc_html( $folder ), esc_html( $image ) ) . '</p>';	
		}
		if ( ! empty( $image ) && $post_id ) {
			// try to find the image
			$attachments = get_posts( array( 'numberposts' => -1, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $post_id, 'post_status' => null  ) );
			$attachment_id = 0;
			if ( ! empty( $attachments ) ) {		
				foreach( $attachments as $attachment ) {
					$wp_src = wp_get_attachment_image_src( $attachment->ID, 'full' );
					if( $image == basename( $wp_src[0] ) ) {
						$attachment_id = $attachment->ID;
						break;
					}	else if ( sanitize_file_name( $image ) == basename( $wp_src[0] ) ) {
						$attachment_id = $attachment->ID;
						break;
					}	else {
						$pathinfo = pathinfo( $image );
						if ( $pathinfo['filename'] == $attachment->post_title ) {
							$attachment_id = $attachment->ID;
							break;
						} else if ( $pathinfo['filename'] == $attachment->post_excerpt ) {
							$attachment_id = $attachment->ID;
							break;
						}
					}		
				}
			}
			if ( ! $attachment_id )
				return '<p class="error">' .  sprintf( __( 'Apologies, but no image could be matched in shortcode <code>[lg_image folder="%s" image="%s"]</code>', 'lazyest-gallery' ), esc_html( $folder ), esc_html( $image ) ) . '</p>';
			
			$attachment = get_post( $attachment_id );
			if ( empty( $caption ) )
				$caption = $attachment->post_excerpt;
			if ( empty( $caption ) )
				$caption = $attachment->post_title;
			$caption = esc_html( $caption );		
						
			if ( ! defined( 'LAZYEST_GALLERY_SHORTCODE' ) )
				define( 'LAZYEST_GALLERY_SHORTCODE', true );
			
			$wp_sr = wp_get_attachment_image_src( $attachment->ID, $display );
			$width = 10 + $wp_src[1];
			$link   = lazyest_frontend()->add_attr_to_link( wp_get_attachment_link( $attachment->ID, $display ), $attachment->ID );			
			$output = "
			<div id='attachment_{$attachment->ID}' class='wp-caption align{$align}' style='width:{$width}px'>
				$link
				<p class='wp-caption-text'>$caption</p>
			</div>
			";
			return $output;	
		}
		return '<p class="error">' . __( 'Apologies, but no folder nor an image could be matched in shortcode <code>[lg_image]</code>', 'lazyest-gallery' ) . '</p>';
	}
	
	/**
	 * Lazyest_Shortcodes::lg_slideshow_shortcode()
	 * Support for the <code>[lg_slideshow]</code> shortcode
	 * @deprecated 2.0.0
	 * @deprecated use Lazyest_Shortcodes::slideshow_shortcode()
	 * 
	 * @since 0.12.0
	 * @param array $attr
	 * @return string html markup for slideshow
	 */
	function lg_slideshow_shortcode( $attr ) {
		$attr[0] = 'lg_slideshow';
		if ( isset( $attr['display'] ) )
			switch( $attr['display'] ) {
				case 'thumb' :
					$attr['display'] = 'thumbnail';
					break;
				case 'slide' :
					$attr['display'] = 'large';
					break;
				case 'image' :
					$display = 'full';
					break;
				default :
					$attr['display'] = 'medium';								
			}
		return $this->lazyest_slideshow( $attr );
	}

} // LAzyest_Shortcodes